#!/bin/sh
echo -n 'Page Name:'
read page

author='吴建涛(fortomorrow@163.com)'
date=`date`

#js目录
mkdir -p app/$page/mods
#less目录
mkdir -p app/$page/style
#template目录
mkdir -p app/$page/template

echo "/**
 * Page: $page
 * Author: $author
 * Date: $date
 * Note: 不要将任何目录命名为config.js中path定义的路径的名字，否则requirejs寻找文件路径会发生错误
 */
require([], function(){
});
" >> app/$page/index.js
echo "app/$page/index.js 创建成功"

echo "/**
 * Page: $page
 * Author: $author
 * Date: $date
 */
//@import (inline) '../third/bootstrap.min.css';
//@import (inline) '../third/normalize.min.css';
" >> app/$page/index.less
touch app/$page/index.css
echo "app/$page/index.less 创建成功"

echo "<!DOCTYPE html>
<html lang=\"zh\">
<head>
  <meta charset=\"UTF-8\">
  <title>$page</title>

  <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">

  <!--移动端常用
  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\" />
  <meta name=\"apple-mobile-web-app-capable\" content=\"yes\"/>
  <meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black\"/>
  <meta name=\"format-detection\" content=\"telephone=no\"/>
  <script src=\"./third/mbase.js\"></script>
  -->

  <link rel=\"stylesheet\" href=\"$page/index.css\" type=\"text/css\" charset=\"utf-8\">
</head>
<body>
  <script src=\"third/require.min.js\"></script>
  <script src=\"$page/config.js\"></script>
  <script src=\"$page/index.js\"></script>
</body>
</html>
" >> app/${page}.php
echo "app/${page}.php 创建成功"

cat com/config.js | sed -e "s/<%page%>/$page/g" > app/$page/config.js
echo "app/$page/config.js 创建成功"

echo "({
  baseUrl: \".\",
  dir: \"../../build/$page/\",
  mainConfigFile: \"config.js\",
  optimize: \"uglify\",
  inlineText: true,
  stubModules: [\"underscore\", \"text\", \"tpl\"],
  removeCombined: true,
  fileExclusionRegExp: /less/,
  preserveLicenseComments: false,
  modules: [
    {
      name: \"index\",// main script name
      include:[\"index\",\"config\"] // map config inclusion
    }
  ],
  paths: {
    jquery: \"empty:\",
    bootstrap:\"empty:\"
  }
})
" > app/$page/build.js
